home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 September / CHIP Eylül 1998.iso / Slackwar / docs / mini / Quota < prev    next >
Text File  |  1997-08-17  |  11KB  |  335 lines

  1.  
  2.                          HOW TO ENABLE QUOTA ON LINUX
  3.                                        
  4.    
  5.    
  6.    _Last updated: Fri Aug 8 09:45:05 HKT 1997_
  7.    
  8.    
  9.         Preamble: This document is copylefted by Albert M.C. Tam
  10.         (bertie@scn.org). Permission to use, copy, distribute this document for
  11.         non-commerical purposes is hereby granted, provided that the author's /
  12.         editor's name and this notice appear in all copies and/or supporting
  13.         documents; that this document is not modified. This document is
  14.         distributed in hope that it will be useful, but WITHOUT ANY WARRANTY,
  15.         either expressed or implied. While every effort has been taken to
  16.         ensure the accuracy of the information documented herein, the author /
  17.         editor / maintainer assumes NO RESPONSIBILITY for errors, or for
  18.         damages results for the use of the information documented herein.
  19.         
  20.    
  21.    
  22.    
  23.    This document describes how to enable file system quota on a Linux
  24.    host, assigning quota for users and groups, as well as the usage of
  25.    miscellaneous quota commands. It is intended for users running kernel
  26.    2.x (recently tested on RedHat 4.1 running kernel 2.0.27). Users
  27.    running older kernels may need to upgrade to a newer kernel version in
  28.    order to take advantage of quota.
  29.    
  30.    Feel free to send feedbacks or comments to bertie@scn.org if you find
  31.    an error, or if any information is missing. I appreciate it.
  32.    
  33.    
  34.      _________________________________________________________________
  35.    
  36.    
  37.    
  38. What is Quota?
  39.  
  40.    
  41.    
  42.    Quota allows you to specify limits on two aspects of disk storage: the
  43.    number of inodes a user or a group of users may possess; and the
  44.    number of disk blocks that may be allocated to a user or a group of
  45.    users.
  46.    
  47.    The idea behind quota is that users are forced to stay under their
  48.    disk comsumption limit, taking away their ability to comsume unlimited
  49.    disk space on a system.
  50.    
  51.    Quota is handled on a per user, per file system basis. If there is
  52.    more than one file system which a user is expected to create files,
  53.    then quota must be set for each file system seperately.
  54.    
  55. Current Status of Quota on Linux
  56.  
  57.    
  58.    
  59.    Quota support has been integrated into kernel since version 1.3.8x I
  60.    heard. Now it is part of the 2.0 release of the Linux kernel. If your
  61.    system doesn't support quota, I really recommend an upgrade.
  62.    
  63.    Currently, quota works for _ext2_ type file system only.
  64.    
  65. Requirements for Using Quota on Linux
  66.  
  67.    
  68.    
  69.    _Kernel_
  70.    
  71.    The 2.x kernel source is available from
  72.    
  73.    http://sunsite.unc.edu/pub/Linux/kernel/v2.0 
  74.        
  75.    
  76.    
  77.    _Quota software_
  78.    
  79.    Depending on the Linux distribution you have, you may, or may not have
  80.    the quota softwares installed on your system. If you don't, then
  81.    download the quota software source from
  82.    
  83.    ftp://ftp.funet.fi/pub/Linux/PEOPLE/Linus/subsystems/quota/all.tar.gz.
  84.        
  85.        
  86.    
  87.    
  88.    
  89.      _________________________________________________________________
  90.    
  91.    
  92.    
  93. Quota Setup on Linux - Part I: The Configuration
  94.  
  95.    
  96.    
  97.    _1. Reconfigure your kernel_
  98.    
  99.    Reconfigure your kernel and add quota support by typing y to:
  100.    
  101.  
  102.      Quota support (CONFIG_QUOTA) [n] y
  103.  
  104.    
  105.    
  106.    _2. Compile and install the quota softwares_
  107.    
  108.    The quota software source is available from
  109.    
  110.    ftp://ftp.funet.fi/pub/Linux/PEOPLE/Linus/subsystems/quota/all.tar.gz 
  111.        
  112.    
  113.    
  114.    _3. Modify your system init script to check quota and turn quota on at
  115.    boot time _
  116.    
  117.    Here's an example:
  118.    
  119.  
  120.         # Check quota and then turn quota on.
  121.         if [ -x /usr/sbin/quotacheck ]
  122.         then
  123.                 echo "Checking quotas. This may take some time."
  124.                 /usr/sbin/quotacheck -avug
  125.                 echo " Done."
  126.         fi
  127.  
  128.         if [ -x /usr/sbin/quotaon ]
  129.         then
  130.                 echo "Turning on quota."
  131.                 /usr/sbin/quotaon -avug
  132.         fi
  133.  
  134.    
  135.    
  136.    The golden rule is that _always_ turn quota on _after_ your file
  137.    systems in /etc/fstab have been mounted, otherwise quota will fail to
  138.    work. I recommend turning quota on at the end of your system init
  139.    script, or, if you like, right after the part where file systems are
  140.    mounted in your system init script.
  141.    
  142.    _4. Modify /etc/fstab_
  143.    
  144.    Partitions that you have not yet enabled quota normally look something
  145.    like:
  146.    
  147.  
  148.         /dev/hda1       /       ext2    defaults        1       1
  149.         /dev/hda2       /usr    ext2    defaults        1       1
  150.  
  151.    
  152.    
  153.    To enable user quota support on a file system, add "usrquota" to the
  154.    fourth field containing the word "defaults" (_man fstab_ for details).
  155.    
  156.    
  157.  
  158.         /dev/hda1       /       ext2    defaults        1       1
  159.         /dev/hda2       /usr    ext2    defaults,usrquota       1       1
  160.  
  161.    
  162.    
  163.    Replace "usrquota" with "grpquota", should you need group quota
  164.    support on a file system.
  165.    
  166.  
  167.         /dev/hda1       /       ext2    defaults        1       1
  168.         /dev/hda2       /usr    ext2    defaults,grpquota       1       1
  169.  
  170.    
  171.    
  172.    Need both user quota and group quota support on a file system?
  173.    
  174.  
  175.         /dev/hda1       /       ext2    defaults        1       1
  176.         /dev/hda2       /usr    ext2    defaults,usrquota,grpquota       1
  177.   1
  178.  
  179.    
  180.    
  181.    _5. Create quota record "quota.user" and "quota.group"_
  182.    
  183.    Both quota record files, quota.user and quota.group, should be owned
  184.    by root, and read-write permission for root and none for anybody else.
  185.    
  186.    
  187.    Login as root. Go to the root of the partition you wish to enable
  188.    quota, then create quota.user and quota.group by doing:
  189.    
  190.  
  191.         touch /partition/quota.user
  192.         touch /partition/quota.group
  193.         chmod 600 /partition/quota.user
  194.         chmod 600 /partition/quota.group
  195.  
  196.    
  197.    
  198.    _6. Reboot_
  199.    
  200.    Now reboot system for the changes you have made to take effect.
  201.    
  202.    Also note that subsequent partitions you wish to enable quota in the
  203.    future only require step 4, 5, and 6.
  204.    
  205. Quota Setup on Linux - Part II: Assigning Quota for Users and Groups
  206.  
  207.    
  208.    
  209.    This operation is performed with the edquota command (_man edquota_
  210.    for details).
  211.    
  212.    I would normally run _quotacheck_ with the flags _-avug_ to obtain the
  213.    most updated filesystems usage prior to editing quota. This is just a
  214.    personal habit, and not a required step however.
  215.    
  216.    _Assigning quota for a particular user_
  217.    
  218.    Here's an example. I have a user with the login id _bob_ on my system.
  219.    The command "edquota -u bob" takes me into vi (or editor specified in
  220.    my $EDITOR environment variable) to edit quota for user _bob_ on each
  221.    partition that has quota enabled:
  222.    
  223.  
  224.         Quotas for user bob:
  225.         /dev/hda2: blocks in use: 2594, limits (soft = 5000, hard = 6500)
  226.                 inodes in use: 356, limits (soft = 1000, hard = 1500)
  227.  
  228.    
  229.    
  230.    "blocks in use" is the total number of blocks (in kilobytes) a user
  231.    has comsumed on a partition.
  232.    
  233.    "inodes in use" is the total number of files a user has on a
  234.    partition.
  235.    
  236.    _Assigning quota for a particular group_
  237.    
  238.    Now I have a group _games_ on my system. "edquota -g games" takes me
  239.    into the vi editor again to edit quota for the group _games_:
  240.    
  241.  
  242.         Quotas for group games:
  243.         /dev/hda4: blocks in use: 5799, limits (soft = 8000, hard = 10000)
  244.                 inodes in use: 1454, limits (soft = 3000, hard = 4000)
  245.  
  246.    
  247.    
  248.    _Assigning quota for a bunch of users with the same value_
  249.    
  250.    To rapidly set quotas for, say 100 users, on my system to the same
  251.    value as my user _bob_, I would first edit _bob_'s quota information
  252.    by hand, then execute:
  253.    
  254.  
  255.         edquota -p bob `awk -F: '$3 > 499 {print $1}' /etc/passwd`
  256.  
  257.    
  258.    
  259.    assuming that you are using csh, and that you assign your user UID's
  260.    starting with 500.
  261.    
  262.    In addition to edquota, there are 3 terms which you should familiarize
  263.    yourself with: Soft Limit, Hard Limit, and Grace Period.
  264.    
  265.    _Soft Limit_
  266.    
  267.    _Soft limit_ indicates the maximum amount of disk usage a quota user
  268.    has on a partition. When combined with _grace period_, it acts as the
  269.    border line, which a quota user is issued warnings about his impending
  270.    quota violation when passed.
  271.    
  272.    _Hard Limit_
  273.    
  274.    _Hard limit_ works _only_ when _grace period_ is set. It specifies the
  275.    absolute limit on the disk usage, which a quota user can't go beyond
  276.    his _hard limit_.
  277.    
  278.    _Grace Period_
  279.    
  280.    Executed with the command "edquota -t", _grace period_ is a time limit
  281.    before the _soft limit_ is enforced for a file system with quota
  282.    enabled. Time units of sec(onds), min(utes), hour(s), day(s), week(s),
  283.    and month(s) can be used. This is what you'll see with the command
  284.    "edquota -t":
  285.    
  286.  
  287.         Time units may be: days, hours, minutes, or seconds
  288.         Grace period before enforcing soft limits for users:
  289.         /dev/hda2: block grace period: 0 days, file grace period: 0 days
  290.  
  291.    
  292.    
  293.    Change the 0 days part to any length of time you feel reasonable. I
  294.    personally would choose 7 days (or 1 week).
  295.    
  296.    
  297.      _________________________________________________________________
  298.    
  299.    
  300.    
  301. Miscellaneous Quota Commands
  302.  
  303.    
  304.    
  305.    _Quotacheck_
  306.    
  307.    Quotacheck is used to scan a file system for disk usages, and updates
  308.    the quota record file "quota.user" to the most recent state. I
  309.    recommend running quotacheck at system bootup, or via cronjob
  310.    periodically (say, every week?).
  311.    
  312.    _Repquota_
  313.    
  314.    Repquota produces a summarized quota information for a file system.
  315.    Here is a sample output repquota gives:
  316.    
  317.  
  318.         # repquota -a
  319.                                 Block limits               File limits
  320.         User            used    soft    hard  grace    used  soft  hard  grace
  321.         root      --  175419       0       0          14679     0     0
  322.         bin       --   18000       0       0            735     0     0
  323.         uucp      --     729       0       0             23     0     0
  324.         man       --      57       0       0             10     0     0
  325.         user1     --   13046   15360   19200            806  1500  2250
  326.         user2     --    2838    5120    6400            377  1000  1500
  327.  
  328.    
  329.    
  330.    _Quotaon and Quotaoff_
  331.    
  332.    Quotaon is used to turn on quota accouting; quotaoff to turn it off.
  333.    Actually both files are similar. They are executed at system startup
  334.    and shutdown.
  335.